package edu.hubu.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import net.moon.jpa.model.BaseEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author moonlan
 * date 2020/11/14 10:45
 */
@SuppressWarnings(value = "unused")
@Entity
@Table(name = "course_time")
//逻辑删除注解，删除sql变成了update
@SQLDelete(sql = "update course_time set course_time_is_deleted = true where course_time_id = ?")
//where条件带上了逻辑删除条件
@Where(clause = "course_time_is_deleted = false")
@ApiModel("一天的课程时间")
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler", "fieldHandler"})
public class CourseDailyTime extends BaseEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "snowflakeId")
    @GenericGenerator(name = "snowflakeId", strategy = "edu.hubu.commons.SnowflakeId", parameters = {@org.hibernate.annotations.Parameter(name = "prefix", value = "COURSE-TIME")})
    @Column(name = "course_time_id")
    @ApiModelProperty(value = "course的id", position = 1)
    private String courseTimeId;

    @Column(name = "course_time_time")
    @ApiModelProperty(value = "课程时间", position = 12)
    private Integer courseTime;

    @ManyToMany(mappedBy = "studentCourseTime", fetch = FetchType.LAZY)
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    private List<StudentCourse> studentCourses = new ArrayList<>();

    @ManyToMany(mappedBy = "teacherCourseTime", fetch = FetchType.LAZY)
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    private List<TeacherCourse> teacherCourses = new ArrayList<>();

    @Column(name = "course_time_is_forbidden")
    @ApiModelProperty(value = "课程时间是否被禁用", position = 12)
    private boolean courseTimeIsForbidden = false;

    @Column(name = "course_time_is_deleted")
    @ApiModelProperty(value = "课程时间是否被删除", position = 13)
    private boolean courseTimeIsDeleted = false;

    public CourseDailyTime(String courseTimeId, Integer courseTime, List<StudentCourse> studentCourses, List<TeacherCourse> teacherCourses, boolean courseTimeIsForbidden, boolean courseTimeIsDeleted) {
        this.courseTimeId = courseTimeId;
        this.courseTime = courseTime;
        this.studentCourses = studentCourses;
        this.teacherCourses = teacherCourses;
        this.courseTimeIsForbidden = courseTimeIsForbidden;
        this.courseTimeIsDeleted = courseTimeIsDeleted;
    }

    public CourseDailyTime() {
    }

    public static CourseDailyTimeBuilder builder() {
        return new CourseDailyTimeBuilder();
    }

    public String getCourseTimeId() {
        return this.courseTimeId;
    }

    public Integer getCourseTime() {
        return this.courseTime;
    }

    public List<StudentCourse> getStudentCourses() {
        return this.studentCourses;
    }

    public List<TeacherCourse> getTeacherCourses() {
        return this.teacherCourses;
    }

    public boolean isCourseTimeIsForbidden() {
        return this.courseTimeIsForbidden;
    }

    public boolean isCourseTimeIsDeleted() {
        return this.courseTimeIsDeleted;
    }

    public void setCourseTimeId(String courseTimeId) {
        this.courseTimeId = courseTimeId;
    }

    public void setCourseTime(Integer courseTime) {
        this.courseTime = courseTime;
    }

    public void setStudentCourses(List<StudentCourse> studentCourses) {
        this.studentCourses = studentCourses;
    }

    public void setTeacherCourses(List<TeacherCourse> teacherCourses) {
        this.teacherCourses = teacherCourses;
    }

    public void setCourseTimeIsForbidden(boolean courseTimeIsForbidden) {
        this.courseTimeIsForbidden = courseTimeIsForbidden;
    }

    public void setCourseTimeIsDeleted(boolean courseTimeIsDeleted) {
        this.courseTimeIsDeleted = courseTimeIsDeleted;
    }

    public static class CourseDailyTimeBuilder {
        private String courseTimeId;
        private Integer courseTime;
        private List<StudentCourse> studentCourses;
        private List<TeacherCourse> teacherCourses;
        private boolean courseTimeIsForbidden;
        private boolean courseTimeIsDeleted;

        CourseDailyTimeBuilder() {
        }

        public CourseDailyTimeBuilder courseTimeId(String courseTimeId) {
            this.courseTimeId = courseTimeId;
            return this;
        }

        public CourseDailyTimeBuilder courseTime(Integer courseTime) {
            this.courseTime = courseTime;
            return this;
        }

        public CourseDailyTimeBuilder studentCourses(List<StudentCourse> studentCourses) {
            this.studentCourses = studentCourses;
            return this;
        }

        public CourseDailyTimeBuilder teacherCourses(List<TeacherCourse> teacherCourses) {
            this.teacherCourses = teacherCourses;
            return this;
        }

        public CourseDailyTimeBuilder courseTimeIsForbidden(boolean courseTimeIsForbidden) {
            this.courseTimeIsForbidden = courseTimeIsForbidden;
            return this;
        }

        public CourseDailyTimeBuilder courseTimeIsDeleted(boolean courseTimeIsDeleted) {
            this.courseTimeIsDeleted = courseTimeIsDeleted;
            return this;
        }

        public CourseDailyTime build() {
            return new CourseDailyTime(courseTimeId, courseTime, studentCourses, teacherCourses, courseTimeIsForbidden, courseTimeIsDeleted);
        }

        public String toString() {
            return "CourseDailyTime.CourseDailyTimeBuilder(courseTimeId=" + this.courseTimeId + ", courseTime=" + this.courseTime + ", studentCourses=" + this.studentCourses + ", teacherCourses=" + this.teacherCourses + ", courseTimeIsForbidden=" + this.courseTimeIsForbidden + ", courseTimeIsDeleted=" + this.courseTimeIsDeleted + ")";
        }
    }
}
